----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 10111 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Flash of Light"
SPELL.m_sToolTip =	[[Heals the target
					for 40 hit points.]]
SPELL.m_iCoolDown = 2.5
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = false
SPELL.m_sIcon = "devin/blackbetty/spells/priest/exorcism.png"
SPELL.CastTime = 5
SPELL.CastSound = nil
SPELL.m_iSpellType = SPELLTYPE_UTILITY

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	local temptarget = nil
	if(pl.DoingCast)then
		pl:SetNWBool("Casting", false)
		pl:SetNWBool("Casted", false)
		return true
	end
	local spellhit = "devin/blackbetty/weapons/hit/Fire1.wav"
	
	if(target == nil)then
		temptarget = pl
	end
	
	if(target && target:IsValid() && pl:GetPos():Distance(target:GetPos()) < self.m_iRange) then
		self.CastSound = CreateSound( pl, "devin/blackbetty/weapons/travelsounds/HolyMissileLoop.wav" )
		self.CastSound:Play()
		pl:SetNWString("HoldType", "camera")
		pl.DoingCast = true
		pl.CastWhileMoving = true
		net.Start( "SendPlayerCast" )
		local SendTable = {self.CastTime, self.m_sName, Color(51, 255, 51, 155)}
		net.WriteTable(SendTable)
		net.Send(pl)
		
		if (pl:GetPos():Distance(target:GetPos()) < self.m_iRange) then
		
			print("Casted "..self.m_sName.."!")
			ParticleEffectAttach( "light_hands", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
			timer.Simple(self.CastTime-0.35, function() 
				if(pl and pl:IsValid() and pl:IsPlayer())then
					pl:DoAnimationEvent(ACT_GMOD_GESTURE_MELEE_SHOVE_2HAND) 
				elseif(pl and pl:IsValid() and !pl:IsPlayer())then
					pl:RestartGesture(ACT_RANGE_ATTACK_THROW)
					pl:SetNWBool("Casting", false)
					pl:SetNWBool("Casted", false)
				else
					self.CastSound:Stop()
				end
			end)
			timer.Create("casting_"..pl:GetName().."", self.CastTime, 1, function()
				if !pl or !target then
					pl.DoingCast = false
					self.CastSound:Stop()
					pl:StopParticles()
					return true
				end
				if pl.DoingCast then
					pl:SetNWString("HoldType", "melee2")
					if(SERVER)then
						local dmginfo = nil
					
						dmginfo = DamageInfo()
						dmginfo:SetDamage( -40 )
						dmginfo:SetDamageType( DMG_POISON ) 
						dmginfo:SetAttacker( pl ) 
						dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) )
						pl:EmitSound("devin/blackbetty/weapons/HolyLight.wav", 100, 100)
						pl:TakeDamageInfo( dmginfo )
						ParticleEffect( "impact_light_heal", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), target )
						
					end
					pl:EmitSound("devin/blackbetty/weapons/castsounds/HolyCast.wav", 100, 100)
					pl:SetNWBool("Casting", false)
					pl:SetNWBool("Casted", false)
					pl.DoingCast = false
					self.CastSound:Stop()
					pl:StopParticles()
				end
			end)
		end
	end
end




